package com.teach.config;

import lombok.Data;

/*
    同意返回类
 */
@Data
public class ReturnResult <T> {
    // 返回码
    private Integer returnCode;
    // 返回信息
    private String returnMsg;
    // 返回状态
    private Boolean returnFlag;
    // 返回数据
    private T returnData;

    public Integer getReturnCode() {
        return returnCode;
    }

    public void setReturnCode(Integer returnCode) {
        this.returnCode = returnCode;
    }

    public String getReturnMsg() {
        return returnMsg;
    }

    public void setReturnMsg(String returnMsg) {
        this.returnMsg = returnMsg;
    }

    public Boolean getReturnFlag() {
        return returnFlag;
    }

    public void setReturnFlag(Boolean returnFlag) {
        this.returnFlag = returnFlag;
    }

    public T getReturnData() {
        return returnData;
    }

    public void setReturnData(T returnData) {
        this.returnData = returnData;
    }

    private ReturnResult(Integer returnCode, String returnMsg, Boolean returnFlag, T returnData) {
        this.returnCode = returnCode;
        this.returnMsg = returnMsg;
        this.returnFlag = returnFlag;
        this.returnData = returnData;
    }

    private ReturnResult(Integer returnCode, String returnMsg, Boolean returnFlag) {
        this.returnCode = returnCode;
        this.returnMsg = returnMsg;
        this.returnFlag = returnFlag;
    }

    private ReturnResult() {
    }

    public static ReturnResult success(Integer returnCode, String returnMsg){
        return new ReturnResult(returnCode, returnMsg, true);
    }

    public static <T> ReturnResult <T> success(Integer returnCode, String returnMsg, T returnData){
        return new ReturnResult<T>(returnCode, returnMsg, true, returnData);
    }

    public static ReturnResult error(Integer returnCode, String returnMsg){
        return new ReturnResult(returnCode, returnMsg, false);
    }
}


